package godardbaudrin.rsa;

import godardbaudrin.math.utils.*;
import java.security.interfaces.RSAPrivateKey;
/**
 * 
 * @author Destiny
 *
 */

public class Formulas {

	/**
	 * Method which gives n
	 * @param p
	 * @param q
	 * @return n
	 */
	public double getN(int p, int q){
		return (double)p * q;
	}
	
	/**
	 * Method which gives PiN
	 * @param p
	 * @param q
	 * @return PhiN
	 */
	public double getPhiN(int p, int q){
		return (double)(p-1)*(q-1);
	}
	
	/**
	 * Method which gives e
	 * @param p
	 * @param q
	 * @param PhiN
	 * @return e
	 */
	public double getE(int p, int q, double PhiN){
		Pgcd pgcd = new Pgcd();
		double pgcdValue;
		double higerValue = p > q ? p : q;
			
		for(double e = higerValue; e < PhiN; e++){
			pgcdValue = pgcd.getPgcd(PhiN, e);		
				if(pgcdValue == 1)
					return e;
		}
		
		//The case where the PGCD of p and q is never found, normally this will never happens
		return 0;
	}
	
	/**
	 * Method which gives d
	 * @param p
	 * @param q
	 * @param e
	 * @param PhiN
	 * @return d
	 */
	public double getD(double e, double PhiN){
		long d = 0;
		double result;
		
		while(true){
			result = (e * d) % PhiN;
				if(result == 1 && d != e)
					return d;
			
			System.out.println("Test: "+d);
			d++;
		}

	}
}
	
	